package com.ymatou.iapi.sellerquery.service;

import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.seller.trading.api.parameter.JsonOrderBean;
import com.ymatou.query.seller.trading.api.parameter.Seller.GetSellerOrderByIdResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 根据单个订单号查询Call FreeMaker Template自动生成代码
 */
public class GetSellerOrderByIdCall extends YmatouBaseCall {
	private static String opurl = "api/Seller/GetSellerOrderById";

	public GetSellerOrderByIdCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	// get data
	public JSONObject getData() {
		JSONObject data = null;
		try {
			data = new JSONObject(getReturnData()).getJSONObject("data");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}

	public GetSellerOrderByIdResponse getSellerOrderByIdResponse() {
		return (GetSellerOrderByIdResponse) FormatUtil.GSONToObject(
				DataUtil.Json.parseJsonObj(getData().toString()).toString(),
				GetSellerOrderByIdResponse.class);
	}

	// 返回order bean 对象
	public JsonOrderBean getOrder() {
		String returnJson = null;
		JsonOrderBean order = null;
		try {
			returnJson = getData().getString("Order");
			order = (JsonOrderBean) FormatUtil.GSONToObject(returnJson,
					JsonOrderBean.class);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return order;
	}

}